//导入封装的axios
import request from '@/utils/request.js'


//登录接口
export const loginReq = (loginData)=>{
    var urlSearchParams = new URLSearchParams();
    for (let loginKey in loginData){
        urlSearchParams.append(loginKey,loginData[loginKey])
    }
    return request.post("/user/login",urlSearchParams)

}

//获取用户信息接口
export const getUserReq = () => {
    return request.get('/user/getUserInfo')
}

//3.修改用户信息
export const updateUserReq = (userInfo) => {
    return request.put('/user/update',userInfo)
}

//4.修改用户密码
export const updatePwdReq = (passwordForm) => {
    //使用查询参数方式
    const urlSearchParams = new URLSearchParams();
    //遍历请求参数 去拼接查询参数 username=123&pwd=123
    for(let passwordDataKey in passwordForm){
        urlSearchParams.append(passwordDataKey,passwordForm[passwordDataKey])
    }
    return request.post('/user/updatePwd',urlSearchParams)
}

//4.修改用户头像
export const updateAvatarReq = (avatarUrl) => {
    //使用查询参数方式
    const urlSearchParams = new URLSearchParams();
    urlSearchParams.append('avatarUrl',avatarUrl)
    return request.post('/user/updateAvatar',urlSearchParams)
}

//5.退出登录
export const logoutReq = () => {
    //使用查询参数方式
    return request.post('/user/logout')
}